<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2020/7/23
  Time: 10:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>入党申请</title>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8 ? MYOA_CHARSET : htmlspecialchars($HTML_PAGE_CHARSET))?>" />
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <link rel="stylesheet" href="/lib/layui/layui/css/layui.css?20190817.1">
    <link rel="stylesheet" href="/lib/layui/layui/css/common.css">
    <link rel="stylesheet" href="/lib/layui/layui/css/eleTree.css">
    <script type="text/javascript" src="/js/jquery/jquery-1.9.1.js"></script>
    <script src="/lib/layui/layui/layui.js"></script>
    <script src="/lib/jquery.form.min.js"></script>
    <script src="/lib/layui/layui/js/baseCode/base.js?v=2019080918:09" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" src="/lib/layui/layui/global.js"></script>
    <script src="/js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="/js/attachment/attachView.js" type="text/javascript" charset="utf-8"></script>
    <style>
        dd{
            text-align: left;

        }
        table{
            width: 65%;
            margin: 0 auto;
            margin-bottom: 20px;
        }
        td{
            border: 1px solid #999;
            padding: 6px 0;
            text-align: center;
            height: 40px;
        }
        .fromTr>.fromTd1{
            width: 10%;
        }
        .fromTr>.fromTd2{
            width: 20%;
        }
        .fromTd2{
            padding: 0 !important;
        }
        .fromTrinp{
            width: 94%;
            height: 77%;
            border: none;
            padding: 0 10px;
        }
        input,textarea{
            border: none;
            padding-left: 10px;
        }
        /*input[name="file1"],input[name="file2"]{*/
        /*    width: 30%;*/
        /*    height: 32px;*/
        /*}*/
        .fromTrSpan{
            width: 45%;
            position: absolute;
            left: 0;
            top: 13px;
        }
        #test3Font{
            /*position: relative;*/
            /*top: -31px;*/
            height: 24px;
            line-height: 24px;
            /*left: 17%;*/
            /*width: 78px;*/
        }
        .fromSpan{
            position: absolute;
            width: 50%;
            top: 5px;
            right: 0;
        }
        .layui-disabled, .layui-disabled:hover {
            color: #666!important;
            cursor: not-allowed!important;
        }
        input{
            height: 30px;
        }
        /*.shengqing{*/
        /*    display: flex;*/
        /*    width: 100%;*/
        /*    height: 100%;*/
        /*    border: 1px solid #e6e6e6;*/
        /*    justify-content: center;*/
        /*    align-items: center;*/
        /*}*/
        .layui-form-select .layui-input {
            margin-left: 10px;
            width: 95%;
            height: 32px;
        }
        #sexBox .layui-form-radio{
            float: left;
            margin: 3px 10px 0 20px;
        }
    </style>
</head>
<body>
<div class="maintop clearfix" style="padding: 19px 0;">
    <p style="">
        <img src="/img/document/icon_agentDispatch.png"
             style="margin-left: 35px;margin-bottom: 13px;" alt="">
        <label style="font-family: 微软雅黑;font-size: 22px;margin-left: 10px;">入党申请</label>
        <button class="layui-btn" id="temp" style="float:right;margin: 0 10px;">模板下载</button>
    </p>


</div>
<div class="content">
    <form class="layui-form" action="" lay-filter="example">
        <table class="layui-table"  style="margin: 0 auto;margin-top: 20px;width: 82%;">
            <thead>
            <tr>
                <th colspan="4" style="width: 100%;text-align: center;margin: 20px 0;font-size: 20px;background: #009688;color: white">入党申请表</th>
            </tr>
            </thead>
            <tbody>
            <tr class="fromTr">
                <td class="fromTd1">姓名</td>
                <td class="fromTd2"><input class="fromTrinp"   name="username" type="text" disabled></td>
                <td class="fromTd1">发展阶段</td>
                <td class="fromTd2">
                    <select  name="development" id="development" lay-filter="development" class="fromTrinp" lay-verify="required" >
                        <option value="">请选择</option>
                        <option value="0">申请入党</option>
                        <option value="1" disabled>入党申请审核</option>
                        <option value="2">积极分子</option>
                        <option value="3">发展对象</option>
                        <option value="4">预备党员(未接收)</option>
                        <option value="5">预备党员(已接收)</option>
                        <option value="6">正式党员</option>
                    </select>
                </td>
            </tr>
            <tr class="fromTr">
                <td class="fromTd1">性别</td>
                <td class="fromTd2" id="sexBox"><input type="radio" name="sex" value="0" title="男">
                    <input type="radio" name="sex" value="1" title="女"></td>
                <td class="fromTd1">出生日期</td>
                <td class="fromTd2"><input class="fromTrinp"  name="nativity" id="nativity" type="text"></td>
            </tr>
            <tr class="fromTr">
                <td class="fromTd1">民族</td>
                <td class="fromTd2"><input class="fromTrinp" name="minority" type="text"></td>
                <td class="fromTd1">职务</td>
                <td class="fromTd2"><input class="fromTrinp" name="functionar" type="text" disabled></td>
            </tr>
            <tr class="fromTr">
                <td class="fromTd1">单位（部门）</td>
                <td class="fromTd2"><input class="fromTrinp" name="unit" type="text" disabled></td>
                <td class="fromTd1">所属党支部</td>
                <td class="fromTd2">
<%--                    <input class="fromTrinp" name="pertain" type="text" disabled>--%>
                    <select  name="pertain" id="pertain" class="fromTrinp" lay-verify="required" >
                        <option value="">请选择</option>
                    </select>
                </td>
            </tr>
            <tr class="fromTr" id="report">
                <td class="fromTd1">入党申请书</td>
                <td colspan="3" style="    text-align: left;padding-left: 20px">
                        <span class="fromTrSpan">
                            <span style="padding-left: 10px;">附件：</span>
<%--                            <input type="file" name="file" id="test3" class="" style="opacity: 0;">--%>
                            <button type="button" class="layui-btn" id="test3Font"><i class="layui-icon"></i>上传文件</button>
                        </span>
                </td>
            </tr>

            <tr>
                <td colspan="4" class="shengqing">
                    <button type="button" id="shengqing" class="layui-btn">申请</button>
                </td>
            </tr>
            </tbody>
        </table>
    </form>

</div>
</body>
</html>
<script>
    var duixiang;
    var oldPhase;
    $("#report").css("display","none")
    layui.use(['upload','form','layedit','laydate'], function() {

        var $ = layui.jquery
            , upload = layui.upload
            ,form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;

        /*form.on('select(development)',function (data) {
            if(data.value!= "0"){
                alert
                $("#report").css("display","none")
            }else{
                $("#report").css("display","none")
            }

        })*/
        // 所属党支部的ajax
        $.ajax({
            url: '/orgDepartment/selectSum',
            dataType: 'json',
            type: 'get',
            // data: {
            //     dictNo: "ORG_TYPE"
            // },
            success: function (res) {
                var object = res.obj
                var str = ''
                for (var i = 0; i < object.length; i++) {
                    if(object[i].orgDeptParent==0){
                        str += '<option style="text-align: left" value="' + object[i].orgDeptId + '">' + object[i].orgDeptName + '</option>'
                        var parent = object[i];
                        var count = "";
                        str += alone(object,parent,count);
                      /*  for(var j = 0;j<object.length;j++){
                            if(object[j].orgDeptParent!=0&&object[j].orgDeptParent==object[i].orgDeptId){
                                str += '<option value="' + object[j].orgDeptId + '">|--' + object[j].orgDeptName + '</option>'
                            }
                        }*/
                    }
                }
                $('#pertain').append(str)
                form.render('select');
            }
        })
        function alone(ob,parent,count){
            var str = '';
            count +="--";
            for(var i=0;i<ob.length;i++){
                if(ob[i].orgDeptParent == parent.orgDeptId){
                    str += '<option style="text-align: left" value="' + ob[i].orgDeptId + '">|'+count + ob[i].orgDeptName + '</option>'
                    str += alone(ob,ob[i],count);
                }


            }
            return str;
        }

        //input框回显
        $.ajax({
            type:'get',
            url:'/partyMember/findPartyMember',
            dataType: 'json',
            // data:{phase:0},
            success: function (res) {
                // debugger
                // console.log(res.object)
                var data=res.object
                // console.log(data=='')
                if(data == undefined){
                    $('.shengqing').css('display','block-cell')
                    //user/findUserByuserId?userId=admin   當前登陸人
                    $.ajax({
                        type: 'get',
                        url:"/partyMember/initParty?phase=0",
                        dataType: 'json',
                        success:function(res){
                            duixiang=res.object;
                            var data = res.object;
                            // var sex = "";
                            if(data.sex != undefined || data.sex != "undefined"){
                                if(data.sex == "1" || data.sex == 1){
                                    $("#sexBox").find("input").eq(1).attr("checked",true);
                                    form.render();
                                }else{
                                    $("#sexBox").find("input").eq(0).attr("checked",true);
                                    form.render();
                                }
                            }else{
                                $("#sexBox").find("input").eq(0).attr("checked",true);
                                form.render();
                            }
                            /*var developPhase ='';
                            if(data.developPhase == 0 ){
                                developPhase = '申请入党';
                            }*/
                            var time =layui.util.toDateString( data.birthday , 'yyyy-MM-dd')
                            oldPhase =  data.developPhase;
                            form.val('example', {
                                "username": data.userName // "name": "value"
                                ,"development": data.developPhase //发展阶段
                                ,"nativity": time  //出生日期
                                ,"minority": data.familyName //民族
                                ,"functionar": data.postName//职务
                                ,"unit": data.deptName //单位（部门）
                                ,"pertain": data.parentPedtName //所属党支部
                                ,"name":''  //签名
                                ,"clerk":'' //支部书记预设
                            });
                        }
                    })
                }
                else{
                    duixiang = data;
                    /*$('#shengqing').attr("class","layui-btn layui-btn-disabled")*/
                    $('#shengqing').text("重新申请")

                   /* $('#pertain').attr('disabled','disabled')
                    $('.layui-form input').addClass('layui-disabled').attr('disabled','true')*/
                    //input框赋值
                    //附件获取
                    var attachmentNameApply=data.attachmentNameApply
                    $('#test3Font').css('width','auto')
                    var att1="";
                   /* if(data.developPhase!=0){
                        att1=attachmentNameApply.split(",")
                    }*/
                    $('#test3Font').attr('title',att1[0])
                    $('#test3Font').html(att1[0])
                    $('#test3Font').css('color','#666')
                    $('#test3Font').css('background','none')
                    oldPhase =  data.developPhase;
                    form.val('example', {
                        "username": data.userName // "name": "value"
                        ,"development": data.developPhase //发展阶段
                        ,"nativity": data.birthday  //出生日期
                        ,"minority": data.familyName //民族
                        ,"functionar": data.postName//职务
                        ,"unit": data.deptName //单位（部门）
                        ,"pertain": data.parentPedtId //所属党支部
                        ,"name":''  //签名
                        ,"clerk":'' //支部书记预设
                        // ,"file1":att1[0]
                    });
                    //性别
                    if(data.sex != undefined || data.sex != "undefined"){
                        if(data.sex == "1" || data.sex == 1){
                            $("#sexBox").find("input").eq(1).attr("checked",true);
                            form.render();
                        }else{
                            $("#sexBox").find("input").eq(0).attr("checked",true);
                            form.render();
                        }
                    }else{
                        $("#sexBox").find("input").eq(0).attr("checked",true);
                        form.render();
                    }
                    // 发展阶段
                  /*  if(data.developPhase ==0){
                        $("input[name='development']").val('申请入党')
                    }else if(data.developPhase ==1){
                        $("input[name='development']").val('入党审核')
                    }else if(data.developPhase ==2){
                        $("input[name='development']").val('积极分子')
                    }else if(data.developPhase ==3){
                        $("input[name='development']").val('发展对象')
                    }else if(data.developPhase ==4){
                        $("input[name='development']").val('预备党员未接收')
                    }else if(data.developPhase ==5){
                        $("input[name='development']").val('预备党员已接收')
                    }else if(data.developPhase ==6){
                        $("input[name='development']").val('正式党员')
                    }*/
                }
            }
        })
        //附件上传
        upload.render({
            elem: '#test3Font'
            ,url: '/upload?module=workflow'
            ,accept:'file'
            ,done: function(res, index, upload){
                // debugger
                //假设code=0代表上传成功
                layer.msg('上传成功');
                var data = res.obj
                $('#test3Font').attr('url',data[0].attUrl)
                $('#test3Font').html(data[0].attachName)
                $('#test3Font').css('color','#666')
                $('#test3Font').css('background','none')
            }
        });
        // 点击申请
        $('#shengqing').click(function(){
            var sex = $("#sexBox").find('.layui-form-radioed').prev("input").val();
            if(sex == "男"){
                sex = "0"
            }
            if(sex == "女"){
                sex = "1"
            }
            duixiang.familyName=$("input[name='minority']").val();
            var p = $("#development").val();
            if(p==""||p==undefined||p=="undefined"){
                layer.msg("请选择阶段")
                return;
            }
            if(p=="1"){
                layer.msg("该阶段无法选择,请重新选择!")
                return;
            }
            duixiang.phase ="0";
            duixiang.developPhase=p;
            duixiang.sex=sex;
            duixiang.attrUrls = $('#test3Font').attr('url')
            var birt = $("input[name='nativity']").val();
            var today = new Date();
            var date =  today.getTime() - new Date(birt).getTime();
            var years=Math.floor(date/(24*3600*1000*365))
            debugger
            if(years <18){
                layer.msg("未满18岁不允许提交")
                return;
            }
            duixiang.birthday = birt
            duixiang.parentPedtId = $('#pertain').val();
            duixiang.parentPedtName=$("#pertain").next(".layui-form-select").find("dl dd.layui-this").text();
            if($('#pertain').val()==undefined||$('#pertain').val()==""){
                layer.msg("党支部不能为空");
                return;
            }
            var url = "";
            if(p=="0"){
                url =  "/partyMember/applyParty"
            }else if(p=="2"){
                url =  "/partyMember/selectPhase"
            }else if(p=="3"){
                url =  "/partyMember/selectPhase"
            }else if(p=="4"){
                url =  "/partyMember/selectPhase"
            }else if(p=="5"){
                url =  "/partyMember/selectPhase"
            }else if(p=="6"){
                url =  "/partyMember/selectPhase"
            }
            if(oldPhase!="0"){
                layer.confirm('提交将覆盖之前申请,是否要提交', function(index){
                    doAjax(url)
                    layer.close(index);
                })
            }else if(oldPhase == "0" && p == "0"){//第一次申请
                doAjax(url)
            }else if(oldPhase == "0"){
                doAjax(url)
            }
        })
        laydate.render({
            elem: '#nativity' //指定元素
            , trigger: 'click'

        });
        $("#temp").click(function(){
            $.ajax({
                type: 'post',
                url: '/partyMember/getTemp',
                dataType: 'json',
                data:{phase:0},
                success:function(res){
                    var str = '<div class="clear" style="margin-right:20px;margin-left:20px;">\n' +
                        '                        <table border="0" class="speak_document" style="min-width:50px;width:100%;">\n' +
                        '                        </table>\n' +
                        '                        </div>'
                    layer.open({
                        type: 1,
                        title:[''],
                        area: ['560px', '260px'],
                        shadeClose: true, //点击遮罩关闭
                        content: str,
                        success:function(){
                            var d = res.obj;
                            for(var j =0 ;j < d.length ; j++){
                                debugger
                                var attachment = d[j].attachment;
                                $('.speak_document').append(d[j].flowName+"模板下载")
                                if(attachment == ''){
                                    $('.speak_document').append('<div><span style="color:red">模板为空</span></div>')
                                }else{
                                    $('.speak_document').append(attachView(attachment,'','3','0','1','0'));
                                }
                            }
                            $(document).on('mouseover','.divShow',function () {
                                $(this).find('.operationDiv').show();
                            })
                            $(document).on('mouseout','.divShow',function () {
                                $(this).find('.operationDiv').hide();
                            })
                        },
                        yes:function(index){

                        }
                    })
                }
            })

        })
    })
    function doAjax(url){
        $.ajax({
            type: 'post',
            url: url,
            dataType: 'json',
            data:duixiang,
            success: function (res) {
                if(res.flag == true){
                    $.popWindow('/workflow/work/workform?opflag=1&flowId='+res.object.flowId+'&type=new&flowStep=1&prcsId=1&runId='+res.object.runId);
                    // window.location.herf = 'workflow/work/workform?opflag=1&flowId="'+170+'"&type=new&flowStep=1&prcsId=1&runId="'+106+')'
                }else{
                    layui.layer.msg(res.msg);
                }
            }
        })
    }
    function runWorkListPage() {
        location.reload();
    }
</script>
